// pages/push/push.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region:[],
    show:false,
    isjiantou:true,   //箭头切换
    selectcontent:[],
    value:'',   //选中的值
    valueid:'',  //选中的id
    image:'',
    houseAddress:'',
    houseName:'',
    houseMolding:'',
    housePrice:'',
    houseTitle:'',
    houseText:'',
    latitude:'',
    longitude:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.request({
      url: 'http://www.house.com/index.php/api/houseType',
      success:res=>{
        this.setData({
          selectcontent:res.data.data
        })
      }
    })
  },
  getUserProvince(e)
     {
        this.setData({
            region:e.detail.value     //将用户选择的省市区赋值给region
        })
     },
   // 下拉框收起和下拉
   changejiantou(){
    this.setData({
      isjiantou:!this.data.isjiantou,
      show:true
    })
    
  },
  // 选择数据后回显
  changecontent(e){
    this.setData({
      value:e.currentTarget.dataset.datavalue.house_type_name,
      valueid:e.currentTarget.dataset.datavalue.id,
      isjiantou:true,
      show:false
    })
  },
  /**
   * 图片选择
   */
  imageData(e){
    var imageInfo=e.detail.current[0]
    wx.uploadFile({
      filePath:imageInfo,
      name: 'image',
      url: 'http://www.house.com/index.php/api/imageInfo',
      method:"POST",
      success:res=>{
          var json=JSON.parse(res.data)
          this.setData({
            image:json.data
          })
      }
    })
  },
  /**
   * 获取地址
   */
  houseName(){
    wx.chooseLocation({
      latitude: 0,
      success:res=>{
        this.setData({
          houseAddress:res.address,
          houseName:res.name,
          latitude:res.latitude,
          longitude:res.longitude
        })
       }
    })
    },
    houseMolding(e){
      this.setData({
        houseMolding:e.detail.value
      })  
    },
    housePrice(e){
      this.setData({
        housePrice:e.detail.value
      })  
    },
    houseTitle(e){
      this.setData({
        houseTitle:e.detail.value
      })  
    },
    houseText(e){
      this.setData({
        houseText:e.detail.value
      })  
    },
    /**
     * 发布
     */
    sendPush(){
      wx.navigateTo({
        url: '/pages/payH5/payH5',
      })

      wx.request({
        url: 'http://www.house.com/index.php/api/pushRentingHouse',
        header:{
          token:wx.getStorageSync('token')
        },
        data:{
          region:this.data.region,
          image:this.data.image,
          houseAddress:this.data.houseAddress,
          houseName:this.data.houseName,
          houseMolding:this.data.houseMolding,
          housePrice:this.data.housePrice,
          houseTitle:this.data.houseTitle,
          houseText:this.data.houseText,
          houseType:this.data.valueid,
          houseWay:2,
          latitude:this.data.latitude,
          longitude:this.data.longitude
        },
        method:"POST",
        success:res=>{
          if(res.data.code==200&&res.data.data){
            wx.navigateTo({
              url: '/pages/payH5/payH5?houseId='+res.data.data +"&type="+'2',
            })
        
          }else{
            wx.showToast({
              title:res.data.msg,
              icon:"error"
            })
          
          }
        }
      })
    }
 
})